package com.example;


import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;

public class DaoGen {
    public static void main(String args[])throws Exception{
        //创建了一个用于添加实体（Entity）的模式(Schema)对象。
        Schema schema = new Schema(11,"com.bethinner.demo");
        schema.setDefaultJavaPackageDao("com.bethinner.dao");
        schema.enableKeepSectionsByDefault();

        //一个实体(类)就关联到数据库中的一张表，此处表明为InputString(类名)
        addInputString(schema);
        addTestService(schema);
//        addLocation(schema);
        //生成Dao
        new DaoGenerator().generateAll(schema, "app/src/main/java_gen/");
    }
    private static void addInputString(Schema schema) {
        Entity inputString = schema.addEntity("InputString");
        inputString.addIdProperty().autoincrement();
        inputString.addStringProperty("inString").notNull();


        Entity locationEntity = schema.addEntity("Location");
        locationEntity.addIdProperty().autoincrement();
        locationEntity.addStringProperty("longitude").notNull();
        locationEntity.addStringProperty("latitude").notNull();

        Property inputStringIdProperty = locationEntity.addLongProperty("inputStringId").notNull().getProperty();

        inputString.addToMany(locationEntity, inputStringIdProperty);

        locationEntity.addToOne(inputString, inputStringIdProperty);

    }

    private static void addTestService(Schema schema) {

        Entity inputString = schema.addEntity("TestService");
        inputString.addIdProperty().autoincrement();
        inputString.addStringProperty("name").notNull();
    }
}
